package com.maint.m

import android.app.Activity
import android.content.pm.PackageManager
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat

object PermissionUtil {
    // 推流所需的危险权限
    private val STREAM_PERMISSIONS = arrayOf(
        android.Manifest.permission.CAMERA,
        android.Manifest.permission.RECORD_AUDIO
    )

    // 检查是否拥有所有推流权限
    fun hasAllStreamPermissions(activity: Activity): Boolean {
        return STREAM_PERMISSIONS.all {
            ContextCompat.checkSelfPermission(activity, it) == PackageManager.PERMISSION_GRANTED
        }
    }

    // 申请推流权限（回调在Activity的onRequestPermissionsResult）
    fun requestStreamPermissions(activity: Activity, requestCode: Int) {
        ActivityCompat.requestPermissions(
            activity,
            STREAM_PERMISSIONS,
            requestCode
        )
    }

    // 检查权限申请结果是否全部通过
    fun isPermissionGranted(grantResults: IntArray): Boolean {
        return grantResults.all { it == PackageManager.PERMISSION_GRANTED }
    }
}
